package cn.web.tunnelrobot.controller;

import cn.web.tunnelrobot.dto.RealTimeData;
import cn.web.tunnelrobot.dto.Warning;
import cn.web.tunnelrobot.service.RealTimeDataService;
import cn.web.tunnelrobot.util.Constants;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 实时数据
 * 其他tomcat中调用的实时数据
 *
 * @version 1.0.0
 */
@RestController
@RequestMapping("/realTimeDataController")
@Api(tags = "实时数据接口")
@ApiSort(value = 2)
public class RealTimeDataController {
    @Autowired
    private RealTimeDataService realTimeDataService;

    /**
     * 7个实时数据
     *
     * @return
     */
    @GetMapping("/getRealTimeData")
    @ResponseBody
    @ApiOperation(value = "无", notes = "7个实时数据")
    public RealTimeData getRealTimeData() {
        return Constants.realTimeData;
    }

    /**
     * 7个历史数据分页
     */
    @GetMapping("/getHistoryDatalist")
    @ResponseBody
    @ApiOperation(value = "页码，行数", notes = "7个历史数据分页")
    public HashMap<String, Object> HistoryDatalist(@RequestParam(required = true, name = "page", defaultValue = "1") Integer page,
                                                   @RequestParam(name = "size", defaultValue = "10") Integer size) {
        return realTimeDataService.HistoryDatalist(page, size);
    }

    /**
     * 7个历史数据条件查询
     */
    @GetMapping("/getHistoryDataByTime")
    @ResponseBody
    @ApiOperation(value = "Date", notes = "7个历史数据时间条件查询")
    public HashMap<String, Object> getHistoryDataByTime(String  time) {
        return realTimeDataService.getHistoryDataByTime(time);
    }

    /**
     * 获取充电状态
     */
    @GetMapping("/getChargingsState")
    @ResponseBody
    @ApiOperation(value = "获取充电状态")
    public HashMap<String, Object> getChargingsState() {
        return realTimeDataService.getChargingsState();
    }


    /**
     * 实时信息警告记录
     *
     * @return
     */
    @GetMapping("/getWarningList")
    @ResponseBody
    @ApiOperation(value = "无", notes = "实时信息警告记录")
    public List<Warning> getWarningList() {
        return Constants.warningList;
    }

    /**
     * 机器人实时位置
     *
     * @return
     */
    @GetMapping("/getRobotCurrentPosition")
    @ResponseBody
    @ApiOperation(value = "无", notes = "机器人实时位置")
    public Integer getRobotCurrentPosition() {
        return Constants.robotCurrentPosition;
    }

    @GetMapping("/getsRealMonitoringAddress")
    @ResponseBody
    @ApiOperation(value = "无", notes = "实时监控")
    public List<String> getsRealMonitoringAddress() {
        return Constants.getsRealMonitoringAddress;
    }

    @GetMapping("/getadress")
    @ResponseBody
    @ApiOperation(value = "获取摄像头地址", notes = "")
    public HashMap<String, Object> getsdress(){
        HashMap<String, Object> map = new HashMap<>();
        String value = Constants.doGet(Constants.cameraadress);
        if(value!=null){
            map.put("code", 0);
            map.put("msg",value);
        }else {
            map.put("code", -1);
            map.put("msg","获取失败");
        }
        return map;
    }

}
